package org.arnetminer.tapestry.pages.user;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.PasswordField;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.arnetminer.tapestry.dao.UserDAO;
import org.arnetminer.tapestry.entities.User;
import org.arnetminer.tapestry.pages.Index;

public class Login {
	@Property
    private String usr;
	@Property
    private String pwd;

    @Inject
	private UserDAO usrDao;
	
    @InjectPage
    private Index index;
    
    @InjectPage
    private CreateUser createUser;

    @Component(id = "pwd")
    private PasswordField passwordField;

    @Component
    private Form form;

    private User user;
    
    Object onSuccess()
    {
    	user = new User();
    	user.setPwd(pwd);
    	user.setUsr(usr);
    	if (usrDao.login(user))
    		return index;
        return createUser;
    }

    
}
